package com.goods.controller.business;

import com.goods.business.service.ConsumerService;
import com.goods.common.model.business.Consumer;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business/consumer")
public class ConsumerController {

    @Autowired
    private ConsumerService consumerService;

    //物资去处分页列表展示
    @GetMapping("/findConsumerList")
    public ResponseBean<PageVO<ConsumerVO>> findConsumerList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                             @RequestParam(defaultValue = "10") Integer pageSize,
                                                             String name,
                                                             String address,
                                                             String contact){
        PageVO<ConsumerVO> pageVO = consumerService.findConsumerList(pageNum,pageSize,name,address,contact);
        return ResponseBean.success(pageVO);
    }

    //添加物资去处
    @PostMapping("/add")
    public ResponseBean addConsumer(@RequestBody Consumer consumer){
        consumerService.addConsumer(consumer);
        return ResponseBean.success();
    }

    //编辑物资去处
    @GetMapping("/edit/{id}")
    public ResponseBean editConsumer(@PathVariable Long id){
        Consumer consumer = consumerService.editConsumer(id);
        return ResponseBean.success(consumer);
    }

    //更新物资去处
    @PutMapping("/update/{id}")
    public ResponseBean updateConsumer(@PathVariable Long id,
                                       @RequestBody Consumer consumer){
        consumerService.updateConsumer(consumer);
        return ResponseBean.success();
    }

    //删除物资去处
    @DeleteMapping("/delete/{id}")
    public ResponseBean deleteConsumer(@PathVariable Long id){
        consumerService.deleteConsumer(id);
        return ResponseBean.success();
    }

    //查询所有物资去处
    @GetMapping("/findAll")
    public ResponseBean findAllConsumer(){
        List<Consumer> consumerList = consumerService.findAllConsumer();
        return ResponseBean.success(consumerList);
    }
}
